package com.kk.base.service.home;

import com.kk.base.bean.PageBean;
import com.kk.base.dao.home.HomeUserIdCardDao;
import com.kk.base.entity.home.HomeUserIdCard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;

/**
 * @info :  前台用户实名认证数据库处理层
 */
@Service
public class HomeUserIdCardService {
    
    @Autowired
    private HomeUserIdCardDao homeUserIdCardDao;


    /**
     * 根据前台用户实名认证id查询
     * @param id
     * @return
     */
    public HomeUserIdCard find(Long id){
        return homeUserIdCardDao.find(id);
    }

    /**
     * 根据用户查询
     * @param homeUserId
     * @return
     */
    public HomeUserIdCard findByHomeUser_Id(Long homeUserId){
        return homeUserIdCardDao.findByHomeUser_Id(homeUserId);
    }


    /**
     * 前台用户实名认证添加/编辑操作
     * @param homeUserIdCard
     * @return
     */
    public HomeUserIdCard save(HomeUserIdCard homeUserIdCard){
        return homeUserIdCardDao.save(homeUserIdCard);
    }

    /**
     * 分页查询前台用户实名认证列表
     * @param homeUser
     * @param pageBean
     * @return
     */
    public PageBean<HomeUserIdCard> findList(HomeUserIdCard homeUser, PageBean<HomeUserIdCard> pageBean){
        ExampleMatcher withMatcher = ExampleMatcher.matching().withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains());
        withMatcher = withMatcher.withIgnorePaths("sex");
        Example<HomeUserIdCard> example = Example.of(homeUser, withMatcher);
        Pageable pageable = PageRequest.of(pageBean.getCurrentPage()-1, pageBean.getPageSize());
        Page<HomeUserIdCard> findAll = homeUserIdCardDao.findAll(example, pageable);
        pageBean.setContent(findAll.getContent());
        pageBean.setTotal(findAll.getTotalElements());
        pageBean.setTotalPage(findAll.getTotalPages());
        return pageBean;
    }



    /**
     * 按照前台用户实名认证id删除
     * @param id
     */
    public void delete(Long id){
        homeUserIdCardDao.deleteById(id);
    }

    /**
     * 返回前台用户实名认证总数
     * @return
     */
    public long total(){
        return homeUserIdCardDao.count();
    }
    
    
    
}
